package com.clkj.goldpartner.dao;

import com.clkj.goldpartner.pojo.Customer;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 杨行
 * @date 2021/3/2 9:23
 */
@Repository
public interface CustomerMapper extends Mapper<Customer> {

    /**
     * 获取客户列表
     *
     * @param shop_id
     * @param customer_name
     * @param customer_num
     * @return List<Customer>
     */
    @Select("select * from t_cl_customer where shop_id = #{shop_id} and customer_status = '0' and customer_name like '%${customer_name}%' and customer_num like '%${customer_num}%' ")
    List<Customer> getCustomer(Integer shop_id, String customer_name, String customer_num);

    /**
     * 删除客户列表
     *
     * @param ids
     */
    @Update("update t_cl_customer set customer_status = '1' where customer_id in (${ids}) ")
    void deleteCustomer(@Param("ids") String ids);

    /**
     * 获取最后一位编号
     *
     * @return String
     */
    @Select("select top 1 customer_num from t_cl_customer group by customer_id,customer_num order by customer_id desc ")
    String getCustomer_num();


    /**
     * 获取过期客户
     *
     * @param shop_id
     * @return
     */
    @Select("select * from t_cl_customer where shop_id = #{shop_id} and ( datediff(day,getDate(),licence_date) <= 60 or datediff(day,getDate(),busLicence_date) <= 60 or datediff(day,getDate(),GMP_date) <= 60 or datediff(day,getDate(),code_date) <= 60 )")
    List<Customer> getCustomerWarn(Integer shop_id);
}
